package j2025.j02;

/**
 * @Author 猫大仙
 * 
 */
 public class j0226 {
 public int trap(int[] height) {
  int n = height.length;
  int left = 0,right = n-1;
  int lmax=0,rmax=0;
  int ret = 0;
  while(left<right){
   lmax = Math.max(lmax,height[left]);
   rmax = Math.max(rmax,height[right]);
   if(height[left]<height[right]){
    ret+=lmax-height[left++];
   }else {
    ret+=rmax-height[right--];
   }
  }
  return ret;
 }
}
